package com.oocl.admin_platform.listener;

import java.io.FileNotFoundException;

import java.io.IOException;


import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.log4j.Logger;

import com.oocl.admin_platform.jms.JMSHelper;
import com.oocl.admin_platform.util.Config;

/**
 * Application Lifecycle Listener implementation class MyServletContextListener
 *
 */

public class MyServletContextListener implements ServletContextListener {

	private JMSHelper jmsHelper;
	
	private static Logger logger=Logger.getLogger(MyServletContextListener.class);
    /**
     * Default constructor. 
     */
    public MyServletContextListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    /*
     * step1:get the path by config.util
     * step2:JmsService
     * step3:save the path into the attribute
     * */
    public void contextInitialized(ServletContextEvent sce) {
        // TODO Auto-generated method stub
    	jmsHelper = new JMSHelper();
    	try {
			Config.config(sce.getServletContext());
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			logger.error("listener throw exception "+e.getMessage());
		} catch (IOException e) {
			// TODO Auto-generated catch block
//			e.printStackTrace();
			logger.error("listener throw exception "+e.getMessage());
		}
    	
    	String jmsConnectionString = sce.getServletContext().getAttribute("Jmsconnection").toString();
    	String mqNameString = sce.getServletContext().getAttribute("mqName").toString();
    	
    	jmsHelper.setImageType(sce.getServletContext().getAttribute("imageType").toString());
    	jmsHelper.setPathString(sce.getServletContext().getAttribute("path").toString());
    	jmsHelper.getMessages(jmsConnectionString,mqNameString);
    	
    	
    	
    	
    	
    	
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce) {
        // TODO Auto-generated method stub
    }
	
}
